package br.com.ordersys.framework.utils;

import java.sql.Timestamp;
import java.util.Calendar;
import java.util.GregorianCalendar;

public class DateUtils {
	public static Timestamp clear(Timestamp d, int... fields){
		Calendar cal = new GregorianCalendar();
		cal.setTime(d);
		
		for(int f: fields){
			cal.clear(f);
		}
		
		return new Timestamp(cal.getTimeInMillis());
	}
	
	public static Timestamp truncByDay(Timestamp d){
		return clear(d,Calendar.HOUR,Calendar.MINUTE,Calendar.SECOND,Calendar.MILLISECOND);
	}
	
	public static Timestamp truncByHour(Timestamp d){
		return clear(d,Calendar.MINUTE,Calendar.SECOND,Calendar.MILLISECOND);
	}
}
